
//
//  UploadPhotoTask.m
//  ZooNgonDoiOS
//
//  Created by Anh Jun Linh Tinh on 7/5/12.
//  Copyright (c) 2012 Personal. All rights reserved.
//

#import "UploadPhotoTask.h"
#import "NSString+NSZooString.h"

@implementation UploadPhotoTask
-(id)initWithPhoto:(UIImage *)photo spotId:(NSString *)spotId dishes:(NSMutableArray *)dishes{
    self = [super init];
    if(self){
        _photo = photo;
        _dishesId = dishes;
        _spotId = spotId;
    }
    return self;
}
-(id)initWithPhoto:(UIImage *)photo spotId:(NSString *)spotId{
    self = [super init];
    if(self){
        _spotId = spotId;
        _photo = photo;
    }
    return self;
}
-(void)doExecute{
    RKParams* params = [RKParams params];
    NSData* dataSpotId=[_spotId dataUsingEncoding: [NSString defaultCStringEncoding]];
    [params setData:dataSpotId forParam:@"spot_id"];
 
    if(_dishesId != nil &&  [_dishesId count] > 0){
        NSString * dishes = @"";
        NSString* dish = @"";
        for (int i=0,n=[_dishesId count]; i< n; i++) {
            dish = [NSString stringWithFormat:@"%i", [_dishesId objectAtIndex:i]];
            if(i==0){
                dishes = dish;   
            }else {
              dishes = [NSString appendString:dish,@",",dishes];   
            }
        }
        NSData* dataDishes=[dishes dataUsingEncoding: [NSString defaultCStringEncoding]];
        [params setData:dataDishes forParam:@"dishes"];
    }
    
    [[RKObjectManager sharedManager].client post:@"/photo" params:params delegate:self];  
}

-(void)request:(RKRequest *)request didFailLoadWithError:(NSError *)error{

}

-(void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response{
    
}

@end
